<?php
//$string = "고려대학교 우체국";
//$string = "역삼역";
//$string = "서울 강남구 역삼1동 한솔빌딩";
$string = "서울특별시 강동구 성내1동 562-6 현기빌딩 1층 ";

$conv_str = urlencode($string);

$xml_parser = @xml_parser_create() or die("XML 파서를 생성하지 못했습니다.");

$xml = file_get_contents("http://maps.google.co.kr/maps/geo?output=xml&q=".$conv_str);

/*if(!@xml_parse($xml_parser, $xml, TRUE)) {
die("XML 파싱중 에러가 발생하였습니다.");
} else {
echo "XML 파싱에 성공하였습니다.";
}*/

xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE);
xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, TRUE);

// XML 문서를 파싱하여 그 결과를 두 배열에 저장한다.
xml_parse_into_struct($xml_parser, $xml, $value, $index);


xml_parser_free($xml_parser);
print_r ($conv_str);
print_r ($index);
print_r ($value);
echo ($value[$index["coordinates"][0]][value]);

$geoArr = explode(",", $value[$index["coordinates"][0]][value]);
print_r ($geoArr);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
	<script src="http://maps.google.co.kr/maps?file=api&amp;v=2&amp;key=ABQIAAAA6RfHj_eQ3lQliWy_PsFuLBTBEKVYzM-OVdgoN_HCBQU7QhBD3RTdOzRhss2eTIN5cg4B1w34iZXAuQ" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
function load() 
{
	var map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl()); 
	map.addControl(new GMapTypeControl()); 
	map.setCenter(new GLatLng(<?=$geoArr[1]?>, <?=$geoArr[0]?>), 16);

	var icon_red = new GIcon(); 
	icon_red.image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; 
	icon_red.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; 
	icon_red.iconSize = new GSize(12, 20); 
	icon_red.shadowSize = new GSize(22, 20); 
	icon_red.iconAnchor = new GPoint(6, 20); 
	icon_red.infoWindowAnchor = new GPoint(5, 1);

	var icon_blue = new GIcon(); 
	icon_blue.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png"; 
	icon_blue.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; 
	icon_blue.iconSize = new GSize(12, 20); 
	icon_blue.shadowSize = new GSize(22, 20); 
	icon_blue.iconAnchor = new GPoint(6, 20); 
	icon_blue.infoWindowAnchor = new GPoint(5, 1);

	var icon_green = new GIcon(); 
	icon_green.image = "http://labs.google.com/ridefinder/images/mm_20_green.png"; 
	icon_green.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; 
	icon_green.iconSize = new GSize(12, 20); 
	icon_green.shadowSize = new GSize(22, 20); 
	icon_green.iconAnchor = new GPoint(6, 20); 
	icon_green.infoWindowAnchor = new GPoint(5, 1);
	
	var point = new GLatLng(<?=$geoArr[1]?>, <?=$geoArr[0]?>);
	 
	map.addOverlay(createMarker(point, 1));

	map.addOverlay(createMarker(new GLatLng(37.58919347, 127.0326858), 1));
	map.addOverlay(createMarker(new GLatLng(37.59019347, 127.0306858), 1));

	function createMarker(point, number)  
	{ 
	  var marker = new GMarker(point, icon_green); 
	  GEvent.addListener(marker, "mouseover", function()  
	  { 
	    marker.openInfoWindowHtml("정보 #<b>" + "<?=$string?>" + "</b>"); 
	  }); 
	  GEvent.addListener(marker, "mouseout", function()  
	  { 
	    marker.closeInfoWindow(); 
	  }); 
	  GEvent.addListener(marker, "click", function()  
	  { 
	    alert ("<?=$string?>");
	  });
	  return marker; 
	} 

	/*map.openInfoWindow(map.getCenter(),
	                   document.createTextNode("저여기 살아요"));*/
}
</script>	
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 700px; height: 500px"></div>
  </body>
</html>
<?
//print_r ("http://maps.google.co.kr/maps/geo?output=xml&q=".$conv_str);
//print_r ("aaa".$xml."bb");
?>